cmake_minimum_required(VERSION 3.16)
project(MineSweep VERSION 1.0 LANGUAGES C CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Set up AUTOMOC and some sensible defaults for runtime execution
# When using Qt 6.3, you can replace the code block below with
# qt_standard_project_setup()
set(CMAKE_AUTOMOC ON)
include(GNUInstallDirs)
set(CMAKE_AUTOUIC ON)

find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui)
find_package(Qt${QT_VERSION_MAJOR} OPTIONAL_COMPONENTS Widgets)

# generate qm
execute_process(COMMAND bash "translate_generation.sh"
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

qt_add_executable(MineSweep WIN32 MACOSX_BUNDLE
    MineMap.cpp MineMap.h
    customdialog.cpp customdialog.h customdialog.ui
    main.cpp
    mainwindow.cpp mainwindow.h mainwindow.ui
)
target_link_libraries(MineSweep PRIVATE
    Qt::Core
    Qt::Gui
)


# Resources:
set(hellores_resource_files
    "res/item1.bmp"
    "res/item2.bmp"
    "res/item3.bmp"
    "res/item4.bmp"
)

qt_add_resources(MineSweep "hellores"
    PREFIX
        "/new/prefix1"
    FILES
        ${hellores_resource_files}
)

if((QT_VERSION_MAJOR GREATER 4))
    target_link_libraries(MineSweep PRIVATE
        Qt::Widgets
    )
endif()

install(TARGETS MineSweep
    BUNDLE DESTINATION .
    RUNTIME DESTINATION /opt/apps/com.github.minesweep/files/bin/
)

install(FILES install/com.github.minesweep.desktop DESTINATION /opt/apps/com.github.minesweep/entries/applications)
install(FILES translations/MineSweep_zh_CN.qm DESTINATION /opt/apps/com.github.minesweep/files/bin/translations)
install(FILES install/MineSweep.svg DESTINATION /opt/apps/com.github.minesweep/entries/icons)
install(FILES info/info DESTINATION /opt/apps/com.github.minesweep/)

# Consider using qt_generate_deploy_app_script() for app deployment if
# the project can use Qt 6.3. In that case rerun qmake2cmake with
# --min-qt-version=6.3.
